package com.cos.config.cons;

import com.cos.config.COSConfig;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author Irving
 * @create 2021/7/16
 * @desc 配置文件的值读取出来存在该类下
 **/
public class ConstantAttribute {

    /**
     * secretId
     */
    public static final String COS_SECRET_ID;
    /**
     * secretKey
     */
    public static final String COS_SECRET_KEY;
    /**
     * 地区
     */
    public static final String COS_REGION;
    /**
     * appID
     */
    public static final String COS_APPID;
    /**
     * 下载的线程池大小,提高性能
     */
    public static final int COS_DOWN_THREAD_POOL_SIZE;
    /**
     * 上传的线程池大小,提高性能
     */
    public static final int COS_UP_THREAD_POOL_SIZE;
    /**
     * 上传下载进度的频率,单位毫秒
     */
    public static final long COS_REFRESH_PROGRESS_MILLIS;
    /**
     * 启用分片上传时的文件大小,字节
     */
    public static final long COS_UP_THRESHOLD;
    /**
     * 分片上传时每个分片的大小,字节
     */
    public static final long COS_UP_PART_SIZE;
    /**
     * 断点续传下载使用多线程下载的最小文件大小,,字节
     */
    public static final int COS_DOWN_MULTI_THREAD_THRESHOLD;
    /**
     * 断点续传下载使用的分块大小,字节
     */
    public static final int COS_DOWN_PART_SIZE;

    static {
        InputStream resourceAsStream = COSConfig.class.getClassLoader().getResourceAsStream("cos.properties");
        Properties properties = new Properties();
        try {
            properties.load(resourceAsStream);
            if (resourceAsStream != null) {
                resourceAsStream.close();
            }
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
        COS_SECRET_ID = properties.getProperty("cos.secret.id");
        COS_SECRET_KEY = properties.getProperty("cos.secret.key");
        COS_REGION = properties.getProperty("cos.region");
        COS_APPID = properties.getProperty("cos.app.id");
        COS_DOWN_THREAD_POOL_SIZE = Integer.parseInt(properties.getProperty("cos.download.thread.pool.size"));
        COS_UP_THREAD_POOL_SIZE = Integer.parseInt(properties.getProperty("cos.upload.thread.pool.size"));
        COS_REFRESH_PROGRESS_MILLIS = Long.parseLong(properties.getProperty("cos.refresh.progress.millis"));
        COS_UP_THRESHOLD = Long.parseLong(properties.getProperty("cos.upload.threshold"));
        COS_UP_PART_SIZE = Long.parseLong(properties.getProperty("cos.upload.partSize"));
        COS_DOWN_MULTI_THREAD_THRESHOLD = Integer.parseInt(properties.getProperty("cos.download.multiThreadThreshold"));
        COS_DOWN_PART_SIZE = Integer.parseInt(properties.getProperty("cos.download.partSize"));
    }

}
